package com.stein.app;

import android.app.Application;
import android.content.Context;

import com.stein.entity.DaoMaster;
import com.stein.entity.DaoMaster.OpenHelper;
import com.stein.entity.DaoSession;

public class TApplication extends Application {
	private static DaoMaster daoMaster;
	private static DaoSession daoSession;
	/**
	 * 取得DaoMaster
	 *
	 * @param context
	 * @return
	 */
	public static DaoMaster getDaoMaster(Context context){
		if (daoMaster == null){
			OpenHelper helper = new DaoMaster.DevOpenHelper(context, TConstant.DATABASE_NAME, null);
			daoMaster = new DaoMaster(helper.getWritableDatabase());
		}
		return daoMaster;
	}
	/**
	 * 取得DaoSession
	 *
	 * @param context
	 * @return
	 */
	public static DaoSession getDaoSession(Context context){
		if (daoSession == null){
			if (daoMaster == null){
				daoMaster = getDaoMaster(context);
			}
			daoSession = daoMaster.newSession();
		}
		return daoSession;
	}
}
